package admin_settings_api

import (
	"blog_go/global"
	"blog_go/models/res"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

// 查询site信息
func (AdminSettingsApi) SettingsSiteInfoApi(c *gin.Context) {
	res.OkWithDate(global.Conf.SiteInfo, c)
}

// 查询email信息
func (AdminSettingsApi) SettingsEmailInfoApi(c *gin.Context) {
	res.OkWithDate(global.Conf.Email, c)
}

// 优化写法
func (AdminSettingsApi) SettingsInfoApi(c *gin.Context) {
	var info SettingsUpdateReq
	err := c.ShouldBindUri(&info)
	if err != nil {
		logrus.Error(err)
		res.FailWithCode(res.ParamError, c)
		return
	}
	var result any
	switch info.ConfName {
	case "site_info":
		result = global.Conf.SiteInfo
	case "email":
		result = global.Conf.Email
	case "jwt":
		result = global.Conf.Jwt
	case "qi_niu":
		result = global.Conf.Qiniu
	case "qq":
		result = global.Conf.QQ
	default:
		res.FailWithMessage("没有对应的配置信息", c)
		return
	}
	res.OkWithDate(result, c)
}
